{include file="public/header" /}
<body class="hide-top" style="background-color: #fff">
<div class="login-container">
    <img src="/static/index/img/icon5.png" alt="">
    <div class="submit-content" style="padding-bottom:inherit">
        <div class="submit-hd flex-center" style="color: #000">
            <i class="layui-icon layui-icon-left"></i>找回密码
        </div>
    <div class="login-content forget-content">
        <form action="{:url('login/forget')}" method="post" class="form layui-form">
        <ul class="login-list">
            <li>
                <p>手机号</p>
                <div>
                    <input type="number" name="mobile" id="mobile" placeholder="请填写手机号">
                </div>
            </li>
            {if $sys['is_sms'] == 1}
            <li>
                <p>短信验证码</p>
                <div>
                    <input type="text" name="captcha" placeholder="请输入短信验证码">
                    <span class="code">获取验证码</span>
                </div>
            </li>
            {/if}
            <li>
                <p>登录密码</p>
                <div>
                    <input type="password" name="password" class="psd" placeholder="请填写登录密码">
                </div>
            </li>
            <li>
                <p>确认密码</p>
                <div>
                    <input type="password" name="password_confirm" class="psd" placeholder="请确认登录密码">
                </div>
            </li>
        </ul>
        <p class="save" lay-submit lay-filter="save" formObj=".form">确认</p>
    </form>
    </div>
    </div>
</div>
</body>
{include file="public/footer"/}
<script>
    var os = true;
    var time = 60;
    $('.code').click(function () {
        var mobile = $('#mobile').val();
        if (!mobile) {
            layer.msg('请输入手机号');
            return false;
        }
        if (os !== true) return false;
        os = false;
        layer.load(2);
        $.ajax({
            type: "POST",
            url: "{:url('login/sendSms')}",
            data: {mobile: mobile, action: 'forgetPassword'},
            success: function (data) {
                layer.closeAll();
                console.log(data);
                if (data.code == 1) {
                    layer.msg(data.msg, {time: 1500}, function () {
                        $('.code').html(time + 's');
                        time--;
                        $('.code').siblings();
                        let isTime = setInterval(() => {
                            if (time == 0) {
                                clearInterval(isTime);
                                time = 60;
                                $('.code').html('获取验证码');
                                os = true;
                            }else{
                                $('.code').html(time-- + 's')
                            }
                        }, 1000);
                    });
                } else {
                    os = true;
                    layer.msg(data.msg);
                }
            }
        });
    })
</script>
</html>